﻿using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

namespace Xmart.Expressions.DynamicPredicate;

public interface IDynamicPredicateBuilder
{
    /// <summary>
    /// 构建动态条件为表达式树 
    /// </summary>
    /// <typeparam name="T">参数类型</typeparam>
    /// <param name="model">动态条件模型</param>
    /// <param name="extensions">扩展实现</param>
    /// <param name="propertiesCache">属性缓存</param>
    /// <param name="cancellationToken">撤销令牌</param>
    /// <returns></returns>
    Task<Expression<Func<T, bool>>> BuildAsync<T>(
        DynamicPredicateModel model,
        IDynamicPredicateExtensions? extensions = null,
        Dictionary<string, PropertyInfo>? propertiesCache = null,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 构建动态条件为表达式树 
    /// </summary>
    /// <param name="parameterType">参数类型</param>
    /// <param name="model">动态条件模型</param>
    /// <param name="extensions">扩展实现</param>
    /// <param name="propertiesCache">属性缓存</param>
    /// <param name="cancellationToken">撤销令牌</param>
    Task<LambdaExpression> BuildAsync(
        Type parameterType,
        DynamicPredicateModel model,
        IDynamicPredicateExtensions? extensions = null,
        Dictionary<string, PropertyInfo>? propertiesCache = null,
        CancellationToken cancellationToken = default);
}
